package com.lanyam.travel.base.service.impl;


import com.lanyam.travel.base.entity.BaseInfo;
import com.lanyam.travel.base.entity.vo.BaseInfoVo;
import com.lanyam.travel.base.dao.BaseInfoMapper;
import com.lanyam.travel.base.service.IBaseInfoService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;


@Service
@Transactional
@Slf4j
public class BaseInfoServiceImpl implements IBaseInfoService {

    @Resource
    private BaseInfoMapper baseInfoMapper;

    @Override
    public IPage<BaseInfoVo> getPageBaseInfo (Map<String, Object> queryMap, Integer page, Integer rows) {
        Page<BaseInfoVo> pageSize = new Page<BaseInfoVo>(page, rows);
        Page<BaseInfoVo> pageInfo = baseInfoMapper.getPage(pageSize, queryMap);
        return pageInfo;
    }

    @Override
    public void addBaseInfo(BaseInfo baseInfo) {
        baseInfoMapper.insert(baseInfo);
    }

    @Override
    public void updateBaseInfo(BaseInfo baseInfo) {
        baseInfoMapper.updateById(baseInfo);
    }

    @Override
    public void delById(String id) {
        baseInfoMapper.delById(id);
    }

    @Override
    public BaseInfoVo getData() {
        BaseInfoVo data = baseInfoMapper.getData();
        return data;
    }

    @Override
    public void updateData(BaseInfo baseInfo) {
        int count = baseInfoMapper.getCount();
        if (count > 0)
            baseInfoMapper.updateData(baseInfo);
        else
            baseInfoMapper.insert(baseInfo);
    }
}